﻿@namespace SageKing.Studio.Pages.Base

<MarkdownEditor @bind-Value="@markdownValue"
                SpellChecker="false" AutoDownloadFontAwesome="true" @ref="Markdown1" AutoSaveEnabled="true"
                CustomButtonClicked="@OnCustomButtonClicked">
@*     <Toolbar> 
        <MarkdownToolbarButton Separator Name="Custom button" Value="@markdownValue" Icon="fa fa-star" Title="A Custom Button" />
    </Toolbar> *@
</MarkdownEditor>

<style>
    .ant-modal-body {
        padding: 0px;
        margin: 0px 10px 0 10px;
    }
</style>

@code {
    [Parameter]
    public bool isShow { get; set; }

    [Parameter]
    public string markdownValue { get; set; }

    MarkdownEditor Markdown1;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            if (Markdown1 != null)
            {
                await Markdown1.SetValueAsync(markdownValue);
            }
        }
    }

    public async Task ChangeText(string Value)
    {
        markdownValue = Value;
        if (Markdown1 != null)
        {
            await Markdown1.SetValueAsync(Value);
            StateHasChanged();
            await Markdown1.SetValueAsync(markdownValue);
        }
    }

   public async Task OnCustomButtonClicked(MarkdownButtonEventArgs eventArgs)
    {
        Console.WriteLine(eventArgs.Value);
        await ChangeText(markdownValue);
    }
}
